import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) throws InterruptedException {
        Scanner sc = new Scanner(System.in);
        Repo repo = new Repo(sc.nextLine());
        Thread t1 = new Thread(new Worker1(repo));
        Thread t2 = new Thread(new Worker2(repo));
        t1.start();
        Thread.yield();
        t2.start();
        sc.close();
    }
}

class Repo{
	private String items;
	private String[] strings;
	private boolean flag = true;
	private int i = 0;
	public Repo(String items) {
		this.items = items;
		strings = items.split(" ");
	}
	public int getSize() {
		return strings.length-i;
	} 
	public synchronized void run1(){
		while(!flag){
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(getSize()>0){
				System.out.println(Thread.currentThread().getName() + " finish " + strings[i++]);
				flag = false;
				notify();
			}
		}
	}
	public synchronized void run2(){
		while(flag){
			try {
				wait();
			} catch (Exception e) {
				// TODO Auto-generated catch block
			}
			if(getSize()>0){
				System.out.println(Thread.currentThread().getName() + " finish " + strings[i++]);
				flag = true;
				notify();
			}
		}
	}
}

class Worker1 implements Runnable {
	private Repo repo;

	public Worker1(Repo repo) {
		this.repo = repo;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while(repo.getSize() != 0){
			repo.run1();
		}
	}	
}

class Worker2 implements Runnable {
	private Repo repo;
	public Worker2(Repo repo) {
		this.repo = repo;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while(repo.getSize() != 0){
			repo.run2();
		}
	}	
}